from django.conf import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer



class SecretOauth(object):
    def __init__(self):
        self.serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)

    # 加密
    def dumps(self, data):
        result = self.serializer.dumps(data)

        # result -- bytes
        return result.decode()

    # 解密
    def loads(self, data):
        return self.serializer.loads(data)